<?php defined('InNcPHP') or exit('Access Invalid!');?>

<link rel="stylesheet" type="text/css" href="./resource/css/diyUpload/css/webuploader.css">
<link rel="stylesheet" href="./resource/css/diyUpload/css/demo.css">

<style>
    #img-content { margin: 10px 20px;font-size: 0; }
    #img-content li {
        display: inline-block;
        position: relative;
        height: 100px;
        width: 150px;
        border: 2px dashed #804c2e;
        margin: 0 5px 5px 0;
    }
    .img-list { width: 100%;height: 100%;vertical-align: middle; }
    .img-del {
        position: absolute;
        width: 20px;
        height: 20px;
        background-color: red;
        border-bottom-left-radius: 50%;
        text-align: center;
        font-size: 14px;
        color: #fff;
        top: 0;
        right: 0;
        cursor: pointer;
    }
    .img-del:hover {  background-color: rgba(255,0,0,0.7); }
    .show { display: block; }
    .hide { display: none; }

</style>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3>房型：</h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <?php echo $output['sub_link'];?>

    <div style="clear: both;height:20px; "></div>
    <form id="ticket_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok" />
        <table class="table tb-type2 nobdb">
            <tfoot>
            <!-- 房型名称 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">房型名称:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_spec_name" class="txt" value="<?php echo $output['spec_info']['spec_name'] ?>"></td>
                <td class="vatop tips"><?php echo $lang['ticket_add_title_notice'];?></td>
            </tr>
            <!-- 标签 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">标签:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_label" class="txt" value="<?php echo $output['spec_info']['label'] ?>"></td>
                <td class="vatop tips">例如：28㎡|大床|有窗  多个标签请用‘|’隔开</td>
            </tr>
            <!-- 库存 房间数量 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">房间数量:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_stock" class="txt" value="<?php echo $output['spec_info']['stock'] ?>"></td>
                <td class="vatop tips">该房型的数量</td>
            </tr>
            <!-- 库存 房间数量 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">可住人数:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="true_number" class="txt" value="<?php echo $output['spec_info']['true_number'] ?>"></td>
                <td class="vatop tips">房间可住几人</td>
            </tr>
            <!-- 库存 房间数量 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">面积:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="floorage" class="txt" value="<?php echo $output['spec_info']['floorage'] ?>">㎡</td>
                <td class="vatop tips">房间面积（㎡）</td>
            </tr>
            <!-- 库存 浴室用品 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">浴室用品:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><textarea name="shower_oom" rows="6" class="tarea" id="shower_oom" ><?php echo $output['spec_info']['shower_oom'];?></textarea></td>
                <td class="vatop tips">例如：'拖鞋，浴衣，吹风机，'...等配套设施</td>
            </tr>
            <!-- 库存 浴室用品 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">便利设施:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><textarea name="amenities" rows="6" class="tarea" id="amenities" ><?php echo $output['spec_info']['amenities'];?></textarea></td>
                <td class="vatop tips">例如：'书桌，空调，冰箱'.....等配套设施</td>
            </tr>
            <!-- 成本夹 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">协议价(商家填写):</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="cost_price_all" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> class="txt" value="<?php echo $output['spec_info']['cost_price'] ?>"></td>
                <td class="vatop tips">该价格为商家的成本价</td>
            </tr>
            <!-- 原价 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">原价(平台填写):</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_market_price" class="txt"  <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> value="<?php echo $output['spec_info']['market_price'] ?>"></td>
                <td class="vatop tips">该价格为前端的默认展示价格</td>
            </tr>
            <!-- 销售价 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">销售价(平台填写):</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform"><input type="text" name="all_price" class="txt" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> value="<?php echo $output['spec_info']['price'] ?>"></td>
                <td class="vatop tips">实际销售价</td>
            </tr>

            <!-- 房型封面图片 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">房型封面图:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <span class="type-file-show">
                        <img class="show_image" src="<?php echo ADMIN_TEMPLATES_URL;?>/images/preview.png">
                        <div class="type-file-preview" style="display: none;">
                            <img id="view_img" src="<?php echo $output['spec_info']['surface_img']; ?>" style="max-height: 100px;max-width: 100px;">
                        </div>
                    </span>
                    <span class="type-file-box">
                        <input type='text' name='textfield' id='textfield' class='type-file-text' />
                        <input type='button' name='button' id='button' value='' class='type-file-button' />
                        <input name="thumb" type="file" class="type-file-file" id="image" size="30" hidefocus="true" />
                    </span>
                </td>
                <td class="vatop tips"><?php echo $lang['ticket_add_image_notice'];?></td>
            </tr>
            <!-- 上否上架 -->
           <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">是否上架:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform onoff">
                    <label for="recommend1" class="cb-enable <?php echo $output['spec_info']['is_show'] == 1 ? 'selected' : ''; ?>"><span><?php echo $lang['nc_yes'];?></span></label>
                    <label for="recommend0" class="cb-disable <?php echo $output['spec_info']['is_show'] == 0 ? 'selected' : ''; ?>"><span><?php echo $lang['nc_no'];?></span></label>
                    <input id="recommend1" name="is_show" <?php echo $output['spec_info']['is_show'] == 1 ? 'checked' : ''; ?>  value="1" type="radio">
                    <input id="recommend0" name="is_show" <?php echo $output['spec_info']['is_show'] == 0 ? 'checked' : ''; ?>  value="0" type="radio">
                </td>
                <td class="vatop tips"></td>
            </tr>
            <!-- 是否开启规格 -->
            <tr class="noborder">
                <td colspan="2" class="required">
                    <label class="validation">是否开启规格:</label>
                </td>
            </tr>
            <tr class="noborder">
                <td class="vatop rowform">
                    <input name="open_spec" type="hidden" value="<?php echo $output['spec_info']['open_spec']; ?>">
                    <label><input id="close_spec" type="radio" name="type" value="0" <?php echo $output['spec_info']['open_spec'] == 0?'checked':''; ?>> 关闭</label>
                    <label><input id="open_spec" type="radio" name="type" value="1" <?php echo $output['spec_info']['open_spec'] == 1?'checked':''; ?>> 开启</label>
                </td>
                <td class="vatop tips">若不开启则默认为房型的价格</td>
            </tr>
            <tr id="spec_type" style="display: <?php echo $output['spec_info']['open_spec']==1?'':'none'; ?>">
                <th colspan="2">
                    <a href="JavaScript:void(0);"  class="add_goods_size"  style="display:block; width: 65px; height: 25px; line-height: 1.5rem; background-color: #24CA71;color: #FFF; text-align: center">+ 添加类型</a>
                    您可以添加多种类型及价格；类型名称例如（含早餐双人）（不含早餐双人）....，
                </th>
            </tr>
            <tr id="spec_info" style="display: <?php echo $output['spec_info']['open_spec']==1?'':'none'; ?>">
                <td colspan="2">
                    <table class="table tb-type2 goods ">
                        <tbody class="goods_size1">
                        <tr>
                            <th>序号</th>
                            <th>类型名称</th>
                            <th>标签</th>
                            <th>协议价(平台填写)</th>
                            <th>原价(平台填写)</th>
                            <th>售价(平台填写)</th>
                            <!--<th>房间数量</th>-->
                            <th>是否上架</th>
                            <th> 操作</th>
                        </tr>
            <?php if(empty($output['spec_list'])) {?>
                       <tr>
                            <td class="w10">1<input type="hidden" name="gs_sort[]"  class="gs_sort" value="1"></td>
                            <td class="w15"><input type="text" name="spec_name[]"  class="goods_size"></td>
                            <td class="w15"><input type="text" value="" name="label[]"  class="label"></td>
                           <td class="w15"><input type="text" value="" name="cost_price[]" class="label" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> ></td>
                            <td class="w15"><input type="text" value="0" name="market_price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>  class="goods_first_price"></td>
                           <td class="w15"><input type="text" value="0" name="price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>  class="goods_second_price"></td>
                           <!-- <td class="w10"><input type="text" value="0" name="stock[]"  class="goods_three_price"></td>-->
                            <td class="w10">
                                <select name="spec_is_show[]">
                                    <option value="1">上架</option>
                                    <option value="0">下架</option>
                                </select>
                            </td>
                            <!--<td class="w10"><input type="text" value="0" name="goods_price[]"  class="goods_price"></td>
                            <td class="w10"><input type="text" value="0" name="goods_stock[]"  class="goods_stock"></td>-->
                            <td class="w10"></td>
                           </tr>
            <?php  }else{?>
            <?php foreach($output['spec_list'] as $ke =>$v){ ?>
                <tr >
                    <td class="w10">
                        <?php echo $v['spec_sort'];?><input type="hidden" name="gs_sort[]"  class="gs_sort" value="<?php echo $v['spec_sort'] ?>">
                        <input type="hidden" name="spec_id[]" value="<?php echo $v['spec_id']; ?>">
                    </td>
                    <td class="w15"><input type="text" name="spec_name[]"  class="goods_size" value="<?php echo $v['spec_name']; ?>"></td>
                    <td class="w15"><input type="text" value="<?php echo $v['label'];  ?>" name="label[]"  class="label"></td>
                    <td class="w15"><input type="text" value="<?php echo $v['cost_price'];  ?>" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> name="cost_price[]" class="label"></td>
                    <td class="w15"><input type="text" value="<?php echo $v['market_price']; ?>" name="market_price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>  class="goods_first_price"></td>
                    <td class="w15"><input type="text" value="<?php echo $v['price']; ?>" name="price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>   class="goods_second_price"></td>
                   <!-- <td class="w10"><input type="text" value="<?php /*echo $v['stock'] */?>" name="stock[]"  class="goods_three_price"></td>-->
                    <td class="w10">
                        <select name="spec_is_show[]">
                            <option value="1" <?php echo $v['is_show']==1?"selected":""; ?>>上架</option>
                            <option value="0"  <?php echo $v['is_show']==0?'selected':''; ?>>下架</option>
                        </select>
                    </td>
                    <!--<td class="w10"><input type="text" value="0" name="goods_price[]"  class="goods_price"></td>
                    <td class="w10"><input type="text" value="0" name="goods_stock[]"  class="goods_stock"></td>-->
                    <!--<td class="w10">
                        <a class="delete_size edit" href="index.php?act=hotel&op=spec_edit&spec_id=<?php /*echo $v['spec_id']; */?>" >编辑</a>
                    </td>-->
                    <td class="w10" >
                        <?php if(count($output['spec_list'])>1&&$ke+1==count($output['spec_list'])){ ?>
                            <a class="delete_size delete" data-id="<?php echo $v['spec_id'] ?>" href="JavaScript:void(0);" >删除</a>
                        <?php }else{ ?>

                        <?php } ?>
                    </td>
                </tr>
            <?php  }?>
            <?php  }?>
                        </tbody>
                    </table>
                </td>
            </tr>
            <script>
                var i = <?php echo count($output['spec_list']) ?>;
                $('.add_goods_size').click(function () {
                    $('.delete').hide();
                    i++;
                    var html = ' <tr ><td class="w10">'+i+'<input type="hidden" name="gs_sort[]"  class="gs_sort" value="'+i+'"> </td> <td class="w15"><input type="text" ' +
                        ' name="spec_name[]"  class="goods_size"></td>  <td class="w15"><input type="text" value=""  ' +
                        ' name="label[]"  class="goods_no"></td> +<td class="w15"><input type="text" value="0" name="cost_price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?> class="goods_first_price"></td>' +
                        ' <td class="w15"><input type="text" value="0"  ' +
                        ' name="market_price[]"  <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>  class="goods_area_agent_price"></td>  ' +
                        '<td class="w15"><input type="text" value="0" name="price[]" <?php if($output["admin_info"]["merchant_id"]>0){ ?>  readonly="true"  <?php } ?>  class="goods_unite_price">' +
                        '</td>' +
                        '<td class="w10"><select name="spec_is_show[]"><option value="1">上架</option> <option value="0">下架</option> </select> </td>'+
                        ' <td class="w10"><a class="delete_size delete" href="JavaScript:void(0);" data-id="0">删除</a></td></tr>';

                    $('.goods_size1').append(html);
                });

                $('.goods_size1').on('click','.delete',function () {
                    i--;
                    //上一个 打开删除
                    $('.goods_size1').find('tr').eq($(this).parent().parent().index()-1).find('.delete').show();
                    //$(this).parent().parent('tr').remove();
                    var spec_id = $(this).attr('data-id');
                    var obj = $(this);
                    if(spec_id>0){
                        layer.confirm('您确定删除该规格', {
                            btn: ['确认','取消'] //按钮
                        }, function(){
                            $.ajax({
                                type:'post',
                                url:'index.php?act=hotel&op=delete_spec',
                                data:{spec_id:spec_id},
                                dataType:'json',
                                success:function(data){
                                    if(data.tab == 'success') {
                                        layer.msg(data.info,{icon: 1});
                                        obj.parent().parent('tr').remove();
                                    }else{
                                        layer.msg(data.info,{icon: 5});
                                        return;
                                    }
                                }
                            });
                        }, function(){
                            layer.msg('取消操作',{icon: 5});
                        });
                    }else{
                        obj.parent().parent('tr').remove();
                    }

//                  var rs = $(this).parent().parent('tr').prev('tr').children('td').children('.delete');
//                  rs.show(100);
//                  console.log(rs);
//                  $('.delete').show();

                });

            </script>
            <table class="table tb-type2" id="prompt">
                <tbody>
                <tr class="space odd">
                    <th class="nobg" colspan="12"><div class="title"><h5>房型图册</h5><span class="arrow"></span></div></th>
                </tr>
                <tr>
                    <td>
                        <ul>
                            <li>点击图片上传，再点击右下角开始上传按钮</li>
                        </ul></td>
                </tr>
                </tbody>
            </table>
            <!--  图片列表  -->
            <ul id="img-content">
                <?php foreach ($output['images'] as $img): ?>
                    <li>
                        <img class="img-list" src="<?php echo $img['img_path']; ?>" alt="IMG">
                        <span class="img-del" data-img_id="<?php echo $img['img_id']; ?>">X</span>
                    </li>
                <?php endforeach; ?>
            </ul>

            <!--  上传插件  -->
            <div id="uploader">
                <div class="queueList">
                    <div id="dndArea" class="placeholder">
                        <div id="filePicker"></div>
                        <p>高版本浏览器可将照片拖到这里，单次最多可选30张</p>
                    </div>
                </div>
                <div class="statusBar" style="display:none;">
                    <div class="progress">
                        <span class="text">0%</span>
                        <span class="percentage"></span>
                    </div><div class="info"></div>
                    <div class="btns">
                        <div id="filePicker2"></div><div class="uploadBtn">开始上传</div>
                    </div>
                </div>
            </div>

            <!-- 提交 -->
            <tr class="tfoot">
                <td colspan="2" >
                    <a href="JavaScript:void(0);" class="btn" id="submitBtn">
                        <span><?php echo $lang['nc_submit'];?></span>
                    </a>
                </td>
            </tr>
            </tfoot>
        </table>

    </form>

</div>

<script>
    var UPLOAD_URL = 'index.php?act=hotel&op=ajax_imgs&spec_id=<?php echo $output['spec_info']['spec_id']; ?>';
    $(document).on('click', '.img-del', function () {
        var _this = $(this);
        var img_id = _this.data('img_id');
        layer.confirm('<?php echo $lang['ticket_day_confirm_del']; ?> ', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=hotel&op=delimg', {img_id: img_id}, function (data) {
                if (data.res) {
                    _this.parent().remove();
                    layer.alert('<?php echo $lang['ticket_day_del_succ']; ?>');
                } else {
                    layer.alert('<?php echo $lang['ticket_day_del_fail']; ?>');
                }
            }, 'json');
        });

    });
   // 图文选择
    $("#image").change(function(){
        $("#textfield").val($(this).val());
    });
   //提交表单
    $("#submitBtn").click(function(){
        if ($("#ticket_form").valid()) {
            $("#ticket_form").submit();
        }else{
            $('html,body').animate({scrollTop: $('label.error:visible:eq(0)').offset().top - 70}, 300);
        }

    });
    //关闭规格
    $("#close_spec").click(function(){
        $("#spec_type").hide();
        $("#spec_info").hide();
        $("[name='open_spec']").val(0);
    });
    //开启规格
    $('#open_spec').click(function(){
        $("#spec_type").show();
        $("#spec_info").show();
        $("[name='open_spec']").val(1);
    });
    //表单校验
    $("#ticket_form").validate({
        errorPlacement: function(error, element){
            if (element.attr('type') === 'file') {
                error.appendTo(element.parent().parent().parent().prev().find('td:first'));
            } else {
                error.appendTo(element.parent().parent().prev().find('td:first'));
            }
        },
        rules: {
            merchant_id: 'required',
            all_spec_name: {
                required: true,

            },
            all_label: {
                required: true,
            },
            cate1: 'required',
            /*cate2: 'required',*/
            <?php if($output['admin_info']['merchant_id']==0): ?>
            all_market_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            cost_price:{
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            market_price: {
                required: true,
                number: true,
                min: 0.01,
                max: 9999999
            },
            <?php endif; ?>
            province_id: 'required',
            city_id: 'required',
            area_id: 'required',
            addr: 'required',
            /*thumb: 'required',*/
            face: 'required',
            content: 'required',
            content1: 'required',
            floorage:{
                required: true,
                number: true,
                min: 1,
                max: 9999999
            },
            true_number:'required',
            shower_oom:'required',
            amenities:'required',
        },
        messages : {
            merchant_id: '<?php echo $lang['ticket_add_merchant_null']; ?>',
            all_spec_name: '<?php echo $lang['ticket_add_title_notice']; ?>',
            all_label: '标签不能为空',
            cate1: '<?php echo $lang['ticket_add_cate1_null']; ?>',
            cate2: '<?php echo $lang['ticket_add_cate2_null']; ?>',
            cost_price:'成本价不能为空',
            <?php if($output['admin_info']['merchant_id']==0): ?>
            all_market_price: '展示价格不能为空',
            market_price: '<?php echo $lang['ticket_add_price_notice']; ?>',
            <?php endif; ?>
            province_id: '<?php echo $lang['ticket_add_province_null']; ?>',
            city_id: '<?php echo $lang['ticket_add_city_null']; ?>',
            area_id: '<?php echo $lang['ticket_add_area_null']; ?>',
            addr: '<?php echo $lang['ticket_add_addr_null']; ?>',
            /* thumb: '<?php echo $lang['ticket_add_image_null']; ?>',*/
            face: '<?php echo $lang['ticket_add_image_null']; ?>',
            content: '<?php echo $lang['ticket_add_detail_null']; ?>',
            content1: '<?php echo $lang['ticket_add_tips_null']; ?>',
            floorage:'房间面积不能为空',
            true_number:'可住人数不能为空',
            shower_oom:'浴室设施不能为空',
            amenities:'便利设施不能为空',

        }
    });
</script>
<script type="text/javascript" src="./resource/css/diyUpload/js/webuploader.html5only.min.js"></script>
<script src="./resource/css/diyUpload/js/demo.js"></script>

